A
A
ase20152019-05-27 13:23:37
C++ / C#
ase2015, 2019-05-27 13:23:37

How to make a rating in the game?

There is a game "Find the elements in the picture" there are two different pictures where you need to look for the elements.
It turns out that I need to somehow make a rating, but I can’t.
The bottom line is this : I can’t calculate their passage time (the timer has a countdown, that is, from 3 minutes). And there are problems. You need to somehow calculate how long it took them to find all the items and you need to remember each game! (in order to later display the result of each game)
Here is the code for the whole process:

public Form3()
    {
        InitializeComponent();
        objects = new List<MapObject>();

        objects.Add(new MapObject()
        {
            Name = "Парусник",
            X = 180,
            Y = 34,
            Width = 27,
            Height = 37
        });

        objects.Add(new MapObject()
        {
            Name = "Пароход",
            X = 304,
            Y = 20,
            Width = 49,
            Height = 19
        });

        objects.Add(new MapObject()
        {
            Name = "Кактус",
            X = 369,
            Y = 127,
            Width = 11,
            Height = 20
        });

        objects.Add(new MapObject()
        {
            Name = "Лошадь",
            X = 336,
            Y = 80,
            Width = 18,
            Height = 18
        });

        objects.Add(new MapObject()
        {
            Name = "Дирижер",
            X = 228,
            Y = 156,
            Width = 17,
            Height = 19
        });

        objects.Add(new MapObject()
        {
            Name = "Мяч",
            X = 213,
            Y = 261,
            Width = 20,
            Height = 20
        });

    }

List<MapObject> objects;
private void Timer1_Tick(object sender, EventArgs e)
    {
        tk = --i;
        TimeSpan span = TimeSpan.FromSeconds(tk);
        string label = span.ToString(@"mm\:ss");
        label1.Text = label.ToString();
        if (i <= 0)
        {
            label9.Visible = true;
            label1.Visible = false;
            timer1.Stop();
            pictureBox1.Visible = false;
            pictureBox2.Visible = true;

        }


    }
int i;
int tk;
string c;
private void Button2_Click(object sender, EventArgs e)
    {
        button2.Visible = false;
        pictureBox1.Visible = true;
        i = 180;
        c = "3:00";

        label1.Text = c;
        timer1.Interval = 1000;
        timer1.Enabled = true;
        timer1.Start();
    }
private void PictureBox1_MouseClick(object sender, MouseEventArgs e)
    {
        int currentX = e.X;
        int currentY = e.Y;
        bool FindSome = false;
        for (int i = 0; i < objects.Count; i++)
        {
            if (currentX > (objects[i].X - objects[i].Width / 2) & currentX < (objects[i].X + objects[i].Width / 2)
            & currentY > (objects[i].Y - objects[i].Height / 2) & currentY < (objects[i].Y + objects[i].Height / 2))
            {
                MessageBox.Show("Вы нашли слово : " + objects[i].Name);
                objects[i].IsClicked = true;
                FindSome = true;
            }


        }

        if (!FindSome) TimeDec();



        if (IsAllClicked())
        {
            label8.Visible = true;
            label1.Visible = false;
            timer1.Stop();
            pictureBox1.Visible = false;
            pictureBox2.Visible = false;
        }
    }

private void TimeDec()
    {
        MessageBox.Show("Никуда не попали");

        i -= 5;

    }

private bool IsAllClicked()
    {
        bool AllObjectsClicked = true;
        foreach (MapObject item in objects)
        {
            if (!item.IsClicked)
            {
                AllObjectsClicked = false; break;
            }
        }
        return AllObjectsClicked;
    }

here is the code from the class(mapobject):
class MapObject
{
    public string Name;

    public int X;
    public int Y;

    public int Width;
    public int Height;
    public bool IsClicked = false;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Glebov, 2019-06-06
@GLeBaTi

Maybe this design will help:

//При старте задания
var stopWatch = new Stopwatch();
stopWatch.Start();

// do stuff

//При окончании задания
stopWatch.Stop();
var elapsed = stopWatch.Elapsed;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question