Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Threading;
- namespace entite_CS_1
- {
- public class Entite
- {
- // Propriétés (données membres)
- const int TX = 80;
- const int TY = 24;
- Random rnd = new Random(); // chiffre aléatoire
- float x, y, dx, dy;
- int color;
- int lettre;
- // Constructeurs (fonctions d'initialisation / allocation)
- public Entite()
- {
- Init_alea();
- }
- // Methodes (fonctions membres)
- public void Init_alea()
- {
- x = rnd.Next(TX);
- y = rnd.Next(TY);
- dx = (float)rnd.NextDouble() * 4 - 2;
- dy = (float)rnd.NextDouble() * 4;
- color = rnd.Next(15) + 1;
- lettre = 'A' + rnd.Next(26);
- }
- public void Move()
- {
- x += dx;
- y += dy;
- // contrôle des bords
- if (x < 0)
- {
- x = 0;
- dx = (float)rnd.NextDouble() * 2;
- }
- if (x >= TX)
- {
- x = TX - 1;
- dx = (float)rnd.NextDouble() * -2;
- }
- if (y < 0)
- {
- y = 0;
- dy = (float)rnd.NextDouble() * 2;
- }
- if (y >= TY)
- {
- y = TY - 1;
- dy = (float)rnd.NextDouble() * -2;
- }
- }
- private void Affiche(int color) // C'est une autre variable, il ne s'agit pas de celle au dessus
- {
- ConsoleColor c = (ConsoleColor)color;
- Console.SetCursorPosition((int)x, (int)y);
- Console.ForegroundColor = c;
- Console.Write(Convert.ToChar(lettre)); // Pour avoir la lettre
- /*
- // Ces deux là affichent le code ASCII et pas la lettre correspondante
- Console.Write(lettre);
- Console.Write(lettre.ToString());
- */
- }
- public void Affiche() // Ceci est une surchage (même nom mais pas les mêmes paramètres)
- {
- Affiche(color); // Par contre, celui là, appelle celui tout en haut
- }
- public void Efface()
- {
- Affiche(0); //Il affichera du noir
- }
- public void run()
- {
- Efface();
- Move();
- Affiche();
- }
- static void Main()
- {
- Entite e = new Entite(); // Constructeur par défaut
- while (true)
- {
- e.run();
- Thread.Sleep(150);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement